import request from "@/utils/request";
import { AxiosPromise } from "axios";

/* 获取商品分类列表 */
export function listCategories(queryParams: object) {
  return request({
    url: "/mall-pms/api/v1/categories",
    method: "get",
    params: queryParams,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 获取商品分类级联器树形列表 */
export function listCategoryOptions(): AxiosPromise<OptionType[]> {
  return request({
    url: "/mall-pms/api/v1/categories/options",
    method: "get",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 获取商品分类详情 */
export function getCategoryDetail(id: number) {
  return request({
    url: "/mall-pms/api/v1/categories/" + id,
    method: "get",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 添加商品分类 */
export function addCategory(data: object) {
  return request({
    url: "/mall-pms/api/v1/categories",
    method: "post",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 修改商品分类 */
export function updateCategory(id: number, data: object) {
  return request({
    url: "/mall-pms/api/v1/categories/" + id,
    method: "put",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 删除商品分类 */
export function deleteCategories(ids: string) {
  return request({
    url: "/mall-pms/api/v1/categories/" + ids,
    method: "delete",
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}

/* 选择性修改商品分类 */
export function updateCategoryPart(id: number, data: object) {
  return request({
    url: "/mall-pms/api/v1/categories/" + id,
    method: "patch",
    data: data,
    headers: {
      Authorization: localStorage.getItem("token"),
    },
  });
}
declare type OptionType = {
  value: string;
  label: string;
  checked?: boolean;
  children?: OptionType[];
};
